package cn.iocoder.yudao.module.promotion.api.promotion;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.promotion.api.promotion.dto.PromotionRespDTO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.promotion.PromotionDO;
import cn.iocoder.yudao.module.promotion.service.promotion.PromotionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class PromotionApiImpl implements PromotionApi {

    @Resource
    private PromotionService promotionService;
    @Override
    public  CommonResult<PromotionRespDTO> getPromotionByProductId(@RequestParam("productId") Long productId) {
        PromotionDO promotion = promotionService.getPromotionByProductId(productId);
        return CommonResult.success(BeanUtils.toBean(promotion, PromotionRespDTO.class));
    }
}
